#!/bin/sh

################################################################################
#
#	File:		Load PACESupport.sh
#
#	Contains:	Shell script run during package installation that loads the
#				PACESupport kext based on the current operating system.
#
#	Copyright:	(C) 2006-2009 by PACE Anti-Piracy, all rights reserved.
# 
################################################################################

# Assume no error for now
result=0

# If we're running Leopard or above, we can delete the older kext packages.
VERSION=`uname -r`
MAJOR_VERSION=${VERSION%%.*}
if [ $MAJOR_VERSION -gt 8 ]; then
	if [ -d /System/Library/Extensions/PACESupport.kext ]; then
		chflags -R nouchg /System/Library/Extensions/PACESupport.kext
		/bin/rm -rf /System/Library/Extensions/PACESupport.kext
	fi
	
	if [ -d /System/Library/Extensions/PACESupport2.kext ]; then
		chflags -R nouchg /System/Library/Extensions/PACESupport2.kext
		/bin/rm -rf /System/Library/Extensions/PACESupport2.kext
	fi
fi

# Force the installed kext to have the right permissions and ownership. This
# should not be necessary, but is included as a clean up for customers of ours
# that install the kext wrong. In theory, running our installer, even for the same
# version, should correct any ownership or permissions problems with the kext.
chown -R root:wheel /System/Library/Extensions/PACESupportFamily.kext
find /System/Library/Extensions/PACESupportFamily.kext -type d -exec chmod 755 {} \;
find /System/Library/Extensions/PACESupportFamily.kext -type f -exec chmod 644 {} \;

# Just in case, we set the load and unload scripts to be executable
chmod 755 /System/Library/Extensions/PACESupportFamily.kext/Contents/Resources/paceload
chmod 755 /System/Library/Extensions/PACESupportFamily.kext/Contents/Resources/paceunload

# Use the master kext script to load the correct sub-kext for this OS		
/System/Library/Extensions/PACESupportFamily.kext/Contents/Resources/paceload
result=$?

exit $result